<template>
  <page-header-wrapper>
    <a-card :bordered="false">
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="6" :sm="24">
              <a-form-item label="公司名称">
                <a-input v-model="queryParam.name" placeholder="请输入公司名称" />
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <span class="table-page-search-submitButtons">
                <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
                <a-button style="margin-left: 8px" @click="() => this.queryParam = {}">重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>

      <a-table ref="table" size="default" rowKey="key" :columns="columns" :dataSource="loadData" :alert="false"
        :pagination="pagination" @change="handleTableChange">
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 }}
        </span>
        <span slot="status" slot-scope="text">
          <a-badge :status="text | statusTypeFilter" :text="text | statusFilter" />
        </span>

        <span slot="action" slot-scope="text, record">
          <template>
            <a @click="handleDetail(record)">详细</a>
            <a-divider type="vertical" />
            <a v-if="record.status == 0" @click="handleDelete(record)">取消预约</a>
          </template>
        </span>
      </a-table>
    </a-card>
  </page-header-wrapper>
</template>
<script>
import moment from 'moment'
import { STable, Ellipsis } from '@/components'
import { getRoleList, getServiceList } from '@/api/manage'
import { Modal } from 'ant-design-vue';
import api from '@/api/order/comorder'

const columns = [
  {
    title: '订单编号',
    dataIndex: 'id'
  },
  {
    title: '公司名称',
    dataIndex: 'name',
  },
  {
    title: '人数',
    dataIndex: 'personCount',
  },
  {
    title: '开始日期',
    dataIndex: 'checkStart',
  },
   {
    title: '结束日期',
    dataIndex: 'checkEnd',
  },
    {
    title: '订单金额',
    dataIndex: 'money',
  },
    {
    title: '支付时间',
    dataIndex: 'payTime',
  },
  {
    title: '订单状态',
    dataIndex: 'status',
    scopedSlots: { customRender: 'status' }
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    sorter: true
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: '150px',
    scopedSlots: { customRender: 'action' }
  }
]


const statusMap = {
  0: {
    status: 'processing',
    text: '进行中'
  },
  1: {
    status: 'success',
    text: '已完成'
  },
  2: {
    status: 'default',
    text: '已取消'
  },
  3: {
    status: 'default',
    text: '未支付'
  }
}

export default {
  name: 'TableList',
  components: {
    STable,
    Ellipsis,
  },
  data() {
    this.columns = columns
    return {
      // create model
      confirmLoading: false,
      mdl: null,
      // 查询参数
      queryParam: {
        name: null,
        pageNo: 0,
        pageSize: 10
      },
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0,
        showTotal: total => `共 ${total} 条数据`,
      },
      // 加载数据方法 必须为 Promise 对象
      loadData: [
        { id: 1, name: '公司名称1', num: '10', money: 150, orderTime: '2020-10-10 10:10:10', updatedAt: '2020-10-10 10:10:10', status: 0 },
        { id: 2, name: '公司名称2', num: '26', money: 150, orderTime: '2020-10-10 10:10:10', updatedAt: '2020-10-10 10:10:10', status: 1 },
        { id: 3, name: '公司名称3', num: '35', money: 150, orderTime: '2020-10-10 10:10:10', updatedAt: '2020-10-10 10:10:10', status: 2 },

      ],
      selectedRowKeys: [],
      selectedRows: []
    }
  },
  filters: {
    statusFilter(type) {
      return statusMap[type].text
    },
    statusTypeFilter(type) {
      return statusMap[type].status
    }
  },
  created() {
    this.getList()
  },
  computed: {
    rowSelection() {
      return {
        selectedRowKeys: this.selectedRowKeys,
        onChange: this.onSelectChange
      }
    }
  },
  methods: {
     //  获取列表
    getList() {
      this.loading = true
      api.getList(this.queryParam).then(res => {
        this.loading = false
        this.loadData = res.data.dataList
        this.pagination.total = res.data.totalCount
        this.pagination.current = this.queryParam.pageNo + 1
      }).catch(err => {
        console.log(err);
        this.loading = false
      })
    },
    handleTableChange(e) {
      this.queryParam.pageNo = e.current - 1
      this.getList()
    },
    handleDetail(record) {
      this.$router.push({path: '/comorder/order-list/detail'})
    },
    handleDelete(record) {
      // this.$message.info(`${record.id} 删除成功`)
      Modal.confirm({
        title: '提示',
        content: '确认取消预约？',
        okText: '确认',
        cancelText: '取消',
        onOk() {
          console.log('成功');

        }
      });
    },
    resetSearchForm() {
      this.queryParam = {
        date: moment(new Date())
      }
    }
  }
}

</script>